from langchain_core.tools import tool
from tools.get_mysql import MySQLConnectionFactory
from tools.utility import timer_decorator

mysql_factory = MySQLConnectionFactory()

@tool
@timer_decorator
def get_user_info(customer_id: int) -> dict:        
    """获取用户信息。

    Args:
        customer_id (int): 用户ID

    Returns:
        dict: 包含以下字段的用户信息:
            - customer_id (int): 用户ID
            - username (str): 用户名
            - email (str): 用户邮箱
            - phone_number (str): 用户手机号码
            - registration_time (str): 注册时间
            - name (str): 用户姓名
            - gender (str): 用户性别,可选值:男/女/未知
            - date_of_birth (str): 出生日期
            - address (str): 用户居住地址
            - user_role (str): 用户角色,可选值:普通用户/管理员/VIP用户
            - user_preferences (dict): 用户偏好设置
            - account_status (str): 账户状态,可选值:正常/冻结/注销
            - last_login_time (str): 最后登录时间
    """
    try:
        query = """
        SELECT * FROM customers WHERE customer_id = %s
        """
        results = mysql_factory.execute_query(query, (customer_id,))
        if results:

            results[0].pop("password")
            return results[0]
        else:
            return {"error": "用户不存在"}
    except Exception as e:
        return {"error": str(e)}

if __name__ == "__main__":
    print(get_user_info.invoke({"customer_id": 1}))



